/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package scheduler;

import DB_Manage.DatabaseManager;
import DB_Manage.User;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import org.apache.derby.impl.sql.compile.ParseException;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import scheduler.ScheduledItem;

/**
 *
 * @author user
 */
public class main {
    
    DatabaseManager dbm;
    static ArrayList<ScheduledItem> schedule = new ArrayList<ScheduledItem>();
    static Logger logger = Logger.getLogger(main.class);
    
       private void loadScheduler() throws ParseException, SQLException {
		schedule = dbm.retrScheduleItems();
	}
       
       private static void printScheduledTimes() {
		logger.debug("Their are " + schedule.size() + " items in the schedule.");

		logger.debug("\n\nIterating through schedule using LinkedList iterator");
		//ListIterator<ScheduledItem> itr = schedule.listIterator();
                for (int i=0;i<schedule.size();i++) {
                 ScheduledItem si = schedule.get(i); 
			si.printScheduledTime();
		}
	}
       
       public void main(String[] args) throws ParseException, IOException, ClassNotFoundException, SQLException {

		BasicConfigurator.configure();
		//PropertyConfigurator.configure("/home/oweson/workspace/Ass2/audit_trail/log4j.cfg");
		//PropertyConfigurator.configure("");
		logger.info("Entering application.");

		//                dbm = new DatabaseManager();

		// load the Users from the persistent store.
		//loadUsers();
		//logger.debug("Their are " + listOfUsers.size() + " users in the system.");

		logger.debug("\n\nIterating through schedule using LinkedList iterator");
                
		//DatabaseManager dbm = new DatabaseManager();
		// Create the schedule from the jobs of the users.
		loadScheduler(); // override next run time to soon

		/* Calculate the next run dates for all items in the schedule.
                bm.retrUser( wiyh the userID rom the scheduked item);
        	BillingSite billingSite = new BillingSite();
                dbm.retrBillingSite( with the billingSiteRef from the scheduled item);
		 * calculate the next run date for the item
		 */

		printScheduledTimes();

		logger.debug("Scheduler completed\n\n");
		logger.info("Exiting application.");


	}
}
